<link href="__APP__/message.css" rel="stylesheet" type="text/css" />
<!--tab菜单-->
<div class="feed-nav">
  <div class="nset-hd">
    <h3>我的私信　<span style="font-size:12px;">与<volist name="message.to" id="mb"><php>if ($i > 1) echo '、';</php>&nbsp;<a style="margin:0;color:#0096e6" href="{$mb['user_info']['space_url']}">{$mb['user_info']['uname']}</a>&nbsp;</volist>{:L('PUBLIC_PRIVATE_MESSAGE')}<!--({$message['message_num']})--></span>
      <span class="close-ico right">
        <img onclick="ui.box.close()" src="__THEME__/image/exit.png"/>
      </span>
    </h3>        
  </div>
</div>
</div>
<!--tab菜单/end-->

<div class="scrollarea">
<div class="scrollY" style="width:500px;">

<php>if(CheckPermission('core_normal','send_message')){</php>
<div id="replay" class="replay-section clearfix">
  <div class="article clearfix">
    <dl class="replay-article clearfix">
      <dt style="display:none">{:L('PUBLIC_SENTNOTIFY_MAIL_TO')}：
        <volist name="message.to" id="mb">
        <php>if ($i > 1) echo '、';</php>
        <a href="{$mb['user_info']['space_url']}">{$mb['user_info']['uname']}</a>
        </volist>
      </dt>
      <dd class="info">
        <div class="right mr10"><a href="javascript:;"><img src="{$GLOBALS['ts']['_user']['avatar_small']}" width="50" height="50"></a></div>
        <textarea id="reply_content" cols="" rows="" class="s-textarea" onblur="this.className='s-textarea'" placeholder="您可以按ctrl+enter直接发布回复" onfocus="this.className='s-textarea-focus'"></textarea>
      </dd>
      <dd class="action">
        <a href="javascript:;" class="btn-green-small right" id="replymessage" onclick="doReply();"><span>{:L('PUBLIC_STREAM_REPLY')}</span></a>
        <div class="acts">
          <a class="face-block" href="javascript:;" event-node="message_insert_face" title="表情"><i class="face"></i>表情</a>
          <a class="image-block" href="javascript:;" title="图片" style="display:none"><i class="image"></i>
          <form style='display:inline;display:none;padding:0;margin:0;border:0;outline:none;' >
            <input limit="2" type="file" name="attach" inputname='attach' onchange="core.plugInit('uploadFile',this,'','image')" urlquery='attach_type=message_image&upload_type=image&thumb=1&width=100&height=100&cut=1' hidefocus="true">
          </form>
       </a>
       <a class="file-block" href="javascript:;" title="附件" style="display:none;"><i class="file"></i>
        <form style='display:inline;display:none;padding:0;margin:0;border:0' >
         <input limit="2" type="file" name="attach" inputname='attach' onchange="core.plugInit('uploadFile',this,'','all')" urlquery='attach_type=message_file&upload_type=file' hidefocus="true">
        </form>
       </a>
  <div id="message_face_div_detail"></div>
</div></dd>
    </dl>
  </div>
</div>
<php>}</php>


<!--消息回复列表-->
<div class="reply-lists" id="feed_list"></div>
<p class="moreFoot" id="moreFoot"><a id="load_more_btn" onclick="load_more_message(this)" href="javascript:void(0)"><span class="ico_morefoot"></span>{:L('PUBLIC_MORE')}</a></p>


<script type='text/javascript'>

var list_id = "{$message['list_id']}";
var since_id = "0";
var defalut_since = "{$message['since_id'] - 1}";
var max_id = 0;
var timeout = null;
var type = '{$type}';

$(document).ready(function(){
	$('a[event-node="message_insert_face"]').click(function(){
		var parentDiv = $('#message_face_div_detail')[0];
		core.plugInit('face', this, $('#reply_content'), parentDiv);
	});
    load_more_message('#load_more_btn');
    timeout = setTimeout("load_new_message()", 4000);
});

shortcut('ctrl+return', doReply , {target:'replay'});

function reply_message(name)
{
  var $reply_content = $('#reply_content');
  var reply_content = $reply_content.val();
  reply_content = reply_content ? reply_content + ' ' : '';
  var reply_user = ' ';
  if(-1 == reply_content.indexOf(reply_user)) {
    $reply_content.val(reply_content + reply_user);
  }
  scrolltotop.scrollup();
  $reply_content.focus();
};
var replylock = 0;
function doReply()
{
  if ( replylock == 1 ){
    return;
  }
  var reply_content = $('#reply_content').val();
  var to = "{$message['to'][0]['member_uid']}";
  if('' == reply_content) {
    ui.error('{:L('PUBLIC_COMMENT_MAIL_REQUIRED')}');   
    return false;
  }
  $('#replymessage').html('回复中..');
  var attach_ids = $.trim($('#attach_ids').val());
  $.post("{:U('public/Message/doReply')}", {id:list_id, reply_content:reply_content, to:to, attach_ids:attach_ids}, function(res) {
    if(res.status != '0') {
      $('#reply_content').val('');
      load_new_message();        
    } else {
      ui.error(res.data);
    }
    $('#replymessage').html("<span>{:L('PUBLIC_STREAM_REPLY')}</span>");
    if("undefined" != typeof(core.uploadFile)) {
      core.uploadFile.clean();
      core.uploadFile.removeParentDiv();
    }
  },'json');
  replylock = 1;
  setTimeout(function (){
    replylock = 0;
  },5000);
};
function delSession(ids)
{
  ids = ids.toString();
  if(ids == '') {
    return false;
  }
  $.post("{:U('public/Message/doDeleteSession')}", {ids:ids}, function(res) {
    if (res == '1') {
      ui.success('{:L('PUBLIC_DELETE_SUCCESS')}');
      ids = ids.split(',');
      for(i = 0; i < ids.length; i++) {
        $('#message_'+ids[i]).remove();
      }
      var $message_content_count = $('#message_content_count');
      var message_content_count  = parseInt($message_content_count.html());
      $message_content_count.html(message_content_count - ids.length);
    }else {
      ui.error('{:L('PUBLIC_DELETE_FAIL')}');
    }
  });
};
function load_more_message(o)
{
  var type = 'old';
  var $o = $(o);
  $o.html('{:L('PUBLIC_WATING')}');
  load_more(type);
  $o.html('{:L('PUBLIC_MORE')}');
};
function load_new_message()
{
  var type = 'new';
  clearTimeout(timeout);
  load_more(type);
  timeout = setTimeout("load_new_message()", 4000);
};
function load_more(load)
{
  if('new' == load) {
    var param = {since_id:since_id,list_id:list_id,type:type};
  } else if ('old' == load) {
    var param = {since_id:defalut_since,max_id:max_id,list_id:list_id,type:type};
  }
  $.post(U('public/Message/loadMessage'), param, function(txt){
    if(txt.data) {
      if ('new' == load) {
        $('#feed_list').prepend(txt.data);
        if(txt.since_id > 0) {
          since_id = txt.since_id;
        }
        var $message_content_count = $('#message_content_count');
        var message_content_count  = parseInt($message_content_count.html());
        $message_content_count.html(message_content_count + txt.count);
      } else if ('old' == load) {
        $('#feed_list').append(txt.data);
        max_id = txt.max_id;
        if (since_id <= 0) {
          since_id = txt.since_id;
        }
        if (0 == txt.max_id) {
          $('#moreFoot').css('display', 'none');
        }
      }
    }
  }, 'json');
};
</script>
<script src="__THEME__/js/message/module.message.js"></script>
</div>
</div>